<template>
  <div class="app-container">
    <!--搜索栏-->
    <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="68px">
      <el-form-item label="关键字搜索" label-width="85" prop="keyValue">
        <el-input
          v-model="queryParams.keyValue"
          placeholder="请输入搜索关键字"
          clearable
          style="width: 240px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!--数据列表-->
    <el-table v-loading="loading" :data="dataList">
      <el-table-column type="index" label="序号" width="55" align="center" />
      <el-table-column
        label="风险分析对象"
        prop="riskTargetName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="所属部门"
        prop="deptName"
        width="150"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="重大危险源等级" prop="hazardLevelId">
        <template #default="scope"
          ><span>
            {{ parseHazardLevel(scope.row.hazardLevelId) }}
          </span></template
        >
      </el-table-column>
      <el-table-column
        label="主要负责人"
        prop="chargeUserName"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="技术负责人" prop="skillUserName" />
      <el-table-column label="操作负责人" prop="operateUserName" width="160" />

      <el-table-column
        label="操作"
        align="center"
        width="160"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-tooltip content="详情" placement="top">
            <el-button
              link
              type="primary"
              icon="CircleCheck"
              @click="handleInfo(scope.row)"
              v-hasPermi="['risk:event:query']"
            ></el-button>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.current"
      v-model:limit="queryParams.size"
      @pagination="getList"
    />
    <!--新增对话框-->
    <el-dialog :title="title" v-model="open" width="70%" append-to-body>
      <el-card class="box-card">
        <template #header>
          <div class="card-header">
            <span style="font-size: 18px; font-weight: 800">风险分析对象信息</span>
          </div>
        </template>
        <div class="body">
          <div class="info-item">
            <span>风险分析对象:</span><span>{{ dataInfo.riskTargetName }}</span>
          </div>
          <div class="info-item">
            <span>危险源编码:</span><span>{{ dataInfo.hazardCode }}</span>
          </div>
          <div class="info-item">
            <span>危险源等级:</span
            ><span>{{
              dataInfo.hazardLevelId ? parseHazardLevel(dataInfo.hazardLevelId) : "---"
            }}</span>
          </div>
        </div>
      </el-card>
      <el-card class="box-card" style="margin-top: 12px">
        <template #header>
          <div class="card-header">
            <span style="font-size: 18px; font-weight: 800">主要负责人</span>
          </div>
        </template>
        <div class="body">
          <el-row :gutter="12">
            <el-col :span="8">
              <div class="info-item">
                <span>负责人姓名:</span><span>{{ dataInfo.chargeUserName }}</span>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="info-item">
                <span>联系方式:</span><span>{{ dataInfo.chargeUserPhone }}</span>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="info-item">
                <span>岗位:</span>
                <span>{{ dataInfo.skillUserPost ? dataInfo.skillUserPost : "---" }}</span>
              </div>
            </el-col>
          </el-row>
          <div class="info-item">
            <span>职责描述:</span><span>{{ dataInfo.chargeUserDesc }}</span>
          </div>
        </div>
      </el-card>
      <el-card class="box-card" style="margin-top: 12px">
        <template #header>
          <div class="card-header">
            <span style="font-size: 18px; font-weight: 800">技术负责人</span>
          </div>
        </template>
        <div class="body">
          <el-row :gutter="12">
            <el-col :span="8">
              <div class="info-item">
                <span>负责人姓名:</span><span>{{ dataInfo.skillUserName }}</span>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="info-item">
                <span>联系方式:</span><span>{{ dataInfo.skillUserPhone }}</span>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="info-item">
                <span>岗位:</span>
                <span>{{ dataInfo.skillUserPost ? dataInfo.skillUserPost : "---" }}</span>
              </div>
            </el-col>
          </el-row>
          <div class="info-item">
            <span>职责描述:</span><span>{{ dataInfo.skillUserDesc }}</span>
          </div>
        </div>
      </el-card>
      <el-card class="box-card" style="margin-top: 12px">
        <template #header>
          <div class="card-header">
            <span style="font-size: 18px; font-weight: 800">操作负责人</span>
          </div>
        </template>
        <div class="body">
          <el-row :gutter="12">
            <el-col :span="8">
              <div class="info-item">
                <span>负责人姓名:</span><span>{{ dataInfo.operateUserName }}</span>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="info-item">
                <span>联系方式:</span>
                <span>{{ dataInfo.operateUserPhone }}</span>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="info-item">
                <span>岗位:</span>
                <span>
                  {{ dataInfo.operateUserPost ? dataInfo.operateUserPost : "---" }}
                </span>
              </div>
            </el-col>
          </el-row>
          <div class="info-item">
            <span>职责描述:</span><span>{{ dataInfo.operateUserDesc }}</span>
          </div>
        </div>
      </el-card>
    </el-dialog>
  </div>
</template>
<script setup name="RiskResponsibility">
import { listResponsibility, getResponsibility } from "@/api/prevent/risk/responsibility";
import { listHazardLevel } from "@/api/prevent/setting/setting";
const title = ref(""); //对话框标题
const { proxy } = getCurrentInstance();
const open = ref(false);
const total = ref(0);
const loading = ref(false);
const dataList = ref([]); //包保责任制数据列表
const dataInfo = ref(null);
const hazardLevelOptions = ref([]);
const data = reactive({
  queryParams: {
    current: 1,
    size: 10,
    keyValue: undefined,
  },
  rules: {},
});
const { queryParams } = toRefs(data);

/** 解析重大危险源等级 */
function parseHazardLevel(val) {
  const targetItem = hazardLevelOptions.value.filter((item) => {
    return item.hazardLevelId == val;
  });
  return targetItem[0].hazardLevelName;
}

/** 处理查询 */
function handleQuery() {
  getList();
}
/** 重置 */
function resetQuery() {
  queryParams.value = {
    current: 1,
    size: 10,
  };
}
/** 查询列表数据 */
function getList() {
  listResponsibility(queryParams.value).then((res) => {
    dataList.value = res.data.dataList;
    total.value = res.data.totalNum;
  });
}
/** 处理详情 */
function handleInfo(row) {
  getResponsibility(row.responsibilityId).then((res) => {
    dataInfo.value = res.data;
    open.value = true;
    title.value = "包保责任制详细信息";
  });
}

/** 查询危险源等级下拉树结构 */
function getHazardLevel() {
  listHazardLevel().then((response) => {
    hazardLevelOptions.value = response.data;
  });
}
getHazardLevel();
getList();
</script>
<style scoped lang="scss">
.el-card :deep(.el-card__header) {
  background-color: #e4f0ff !important ;
  color: #0086ff;
}
.info-item {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  height: 42px;
  padding: 18px;
  margin-bottom: 8px;
  font-size: 12px;
  background-color: #f6f8fa;
  border-radius: 5px;
  &:hover {
    padding: 5px;
    font-size: 16px;
  }
  & span:nth-child(1) {
    font-weight: 800;
    color: #9e9e9e;
  }
  & span:nth-child(2) {
    margin-left: 20px;
    font-size: 14px;
  }
}
</style>
